<template>
<div>
  <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
    <div class="iconfont header-abs-back">&#xe604;</div>
  </router-link>
  <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
    <router-link to="/">
      <div class="iconfont header-fixed-back">&#xe604;</div>
    </router-link>
    景点详情
  </div>
</div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 30) {
        let opacity = top / 120
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style scoped lang="stylus">
@import '~styles/varibles.styl'
.header-abs {
  position :absolute
  left:.8rem
  top:.8rem
  width:1.6rem
  height:1.6rem
  line-height:1.6rem
  border-radius:.8rem
  background: rgba(0 0 0 .5)
}
  .header-abs-back {
    color: #fff
    font-size:1rem
    text-align :center
  }
.header-fixed {
  position :fixed
  top:0
  left:.5rem
  right:.5rem
  height:$headerHeight
  line-height:$headerHeight
  text-align:center
  color: #fff
  background: $bgColor
}
.header-fixed-back {
  position :absolute
  top:0
  left:.1rem
  width:1.5rem
  font-size:26px
  text-align: center
  color: #fff
}
</style>
